﻿using IBll;
using IDal;
using Model;

namespace Bll
{
    public class DepartmentBll : IDepartmentbLL
    {

         public DepartmentBll(IBaseDal<Department> baseDa)
        {
            BaseDa = baseDa;
        }

        public IBaseDal<Department> BaseDa { get; }

        public dynamic ShowDepartment(string? name)
        {
            var department = BaseDa.GetAllAnync();
            var linq = from a in department
                       select new
                       {
                           a.DepartmentId,
                           a.DepartmentDate,
                           a.DepartmentImg,
                           a.DepartmentNmae,
                       };

            if (!string.IsNullOrEmpty(name))
            {
                linq = linq.Where(x => x.DepartmentNmae.Contains(name));
            }
            return linq.ToList();

        }
        public async Task<int> AddDepartment(Department department)
        {
            var los = BaseDa.GetAllAnync().FirstOrDefault(x => x.DepartmentNmae == department.DepartmentNmae);
            if (los==null)
            {
                 return await BaseDa.AddAnync(department);


            }
            else
            {
                return -1;
            }
        }

        public List<Department> departments()
        {
            return BaseDa.GetAllAnync().ToList();

        }

    }
}
